import sys
import traceback
from tkinter import messagebox

secret_card_counter = {}
process_first = False

for i in range(0, 806):
    file = '/home/jz/gate_pass_info_device/gate_pass_info_device_{}'.format(i)
    with open(file, 'r',encoding='utf8') as f:
        try:
            for line in f:
                if line == '\n':
                    continue

                line = line.replace('"', '').replace('\n', '').replace("'", "")
                line_split = line.split(',')

                secret_card = line_split[-1]
                if secret_card not in secret_card_counter:
                    secret_card_counter[secret_card] = 0
                secret_card_counter[secret_card] += 1
        except Exception as e:
            messagebox.showinfo("提示", "发生错误{}".format(file))
            traceback.print_exc()
            sys.exit(-1)

    print('{} finish'.format(file))

print('finish read, start write')
with open('secret_card_counter', 'w', encoding='utf8') as f:
    for secret_card, count in secret_card_counter.items():
        line = '{}={}\n'.format(secret_card, count)
        f.write(line)
print('finish write')